<template>
  <div>
    <BasicTable id="inMaintenanceTable" @register="registerTable" >
      <template #tableTitle>
        <img src="/@/assets/twoHome/title-icon.png" alt="">
        <span style="font-size: 24px;color: aliceblue;"> 维保计划 </span>
      </template>
      <template #toolbar >
        <!-- <a-button
         type="primary"
         @click="handleForm({})"
         v-auth="'maintenance:management:inMaintenanceInfo:edit'"
         >
          <Icon icon="i-fluent:add-12-filled" /> {{ t('新增') }}
        </a-button> -->
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup name="InMaintenance" >
  import { unref, ref } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { inMaintenanceInfoDelete, inMaintenanceInfoListData } from '/@/api/maintenance.management/inMaintenanceInfo';
  import { unitEnterpriseDominantListData } from '/@/api/unitmanage/unitEnterpriseDominant';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import { officeTreeData } from '/@/api/sys/office';
  import { registerCoordinateSystem } from 'echarts';
  import dayjs from 'dayjs'; // 引入 dayjs

  const { t } = useI18n('maintenance.management.inMaintenanceInfo');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);

  const getTitle = {
    icon: meta.icon || 'i-ant-design:book-outlined',
    value: meta.title || t('维保任务信息表管理'),
  };

  const inMaintenanceInfoParams = ref({
    title:''
  })

  const EnterpriseParams = ref<Recordable>({
    name:''
  });

  const maintenanceEnterpriseParams = ref<Recordable>({
    name:'',
    dominantType:'maintenance'
  });

  const tableColumns: BasicColumn[] = [
    {
      title: t('单位名称'),
      dataIndex: 'enterpriseName',
      key: 'a.enterprise_name',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('状态'),
      dataIndex:'state',
      key: 'a.state',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        label: t('详情'),
        auth:'maintenance:management:inMaintenanceInfo:edit',
        onClick: () => {
          if (record.id) {
            // 跳转到名为 ViewsMaintenanceManagementInMaintenanceInfoList 的路由，并传递 tid 参数
            router.push({
              name: 'ViewsMaintenanceManagementInMaintenanceInfoList',
              query: { tid: record.id }
            }).catch((error) => {
              console.error('路由跳转出错:', error);
            });
          } else {
            console.error('record.id 未定义，无法跳转');
          }
        },
      },
    ],
  };

  const [registerTable, { reload }] = useTable({
    api: inMaintenanceInfoListData,
    beforeFetch: (params) => {
      // params.tid = tid.value;
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    showTableSetting: true,
    canResize: true,
  });

  function handleSuccess(record: Recordable) {
    reload({ record });
  }
</script>
<style scoped lang="less">
::v-deep #inMaintenanceTable {
  background-color:rgb(9,26,51);
}
::v-deep #inMaintenanceTable .ant-table-body {
  background-color:rgb(9,26,51);
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
::v-deep #inMaintenanceTable .ant-table-thead > tr > th {
  background-color:rgb(9,26,51);
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}

::v-deep #inMaintenanceTable .ant-table-tbody > tr > td {
  background-color:rgb(9,26,51);
  border: 1px solid rgb(192, 192, 249);
}

::v-deep #inMaintenanceTable .ant-table-tbody > tr:hover > td {
  background-color:rgb(9,26,51); /* 可根据需求修改颜色 */
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
::v-deep #inMaintenanceTable .ant-spin-container {
  background-color:rgb(9,26,51);
  color: aliceblue;
  border: 1px solid rgb(192, 192, 249);
}
</style>